package com.neuedu.dbutils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Digest {
    public static String SHA1Digest(String info) {
        byte[] digest = null;
        try {
            MessageDigest alga = MessageDigest.getInstance("SHA-1");
            alga.update(info.getBytes());
            digest = alga.digest();
        } catch (NoSuchAlgorithmException ex) {
            System.out.println("1");
            ex.printStackTrace();
        }
        return byte2hex(digest);
    }

    private static String byte2hex(byte[] b) {
        String hs = "";
        String stmp = "";
        for (int n = 0; n < b.length; n++) {
            stmp = Integer.toHexString(b[n] & 0xFF);
            if (stmp.length() == 1) {
                hs = hs + "0" + stmp;
            } else {
                hs = hs + stmp;
            }
        }
        return hs.toUpperCase();
    }

    public static void main(String[] args) {
      String password = SHA1Digest("1234561520209522646");
      System.out.println("password = " + password);
    }
}
